﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;

namespace KPIS.GERP.Models.SYS
{
    [DataContract, Table("SysUserLoginLogout")]
    public class UserLoginLogout
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DataMember]
        public int UserLoginLogoutId { get; set; }

        [DataMember]
        public int? UserId { get; set; }

        [DataMember]
        public string ClientIp { get; set; }

        [DataMember]
        public string SystemId { get; set; }

        [DataMember]
        public string UserCode { get; set; }

        [DataMember]
        public string FullName { get; set; }

        [DataMember]
        public int? PosId { get; set; }

        [DataMember]
        public DateTime LoginDateTime { get; set; }

        [DataMember]
        public DateTime? LogoutDateTime { get; set; }

        public UserLoginLogout()
        {

        }

        public UserLoginLogout(int? userId, string clientIp, string systemId,
                               string userCode, string fullName, int? posId)
        {
            Login(userId, clientIp, systemId, userCode, fullName, posId);
        }

        public void Login(int? userId, string clientIp, string systemId,
                          string userCode, string fullName, int? posId)
        {
            UserId = userId;
            ClientIp = clientIp;
            SystemId = systemId;
            UserCode = userCode;
            FullName = fullName;
            PosId = posId;
            LoginDateTime = DateTime.Now;
        }

        public void Logout()
        {
            LogoutDateTime = DateTime.Now;
        }
    }
}